<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>分布式锁配置表</title>
    <script type="text/javascript" src="../../scripts/easyui1.7.0/jquery.min.js"></script>
    <script type="text/javascript" src="../../scripts/easyui1.7.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../scripts/easyui1.7.0/easyui.comm.valid.js"></script>
    <script type="text/javascript" src="../../scripts/easyui1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../../scripts/easyui.grid.hide.js"></script>
    <script type="text/javascript" src="../../scripts/Common.js"></script>
    <script type="text/javascript" src="../../scripts/comm.dict.js"></script>
    <script type="text/javascript" src="../../scripts/DateUtils.js"></script>
    <link rel="stylesheet" type="text/css" href="../../scripts/easyui1.7.0/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../scripts/easyui1.7.0/themes/icon.css">

    <style type="text/css">
        #fm {
            margin: 0;
            padding: 10px 20px;
        }

        .ftitle {
            font-size: 14px;
            font-weight: bold;
            padding: 5px 0;
            margin-bottom: 10px;
            border-bottom: 1px solid #ccc;
        }

        .fitem {
            margin-bottom: 5px;
        }

        .fitem label {
            display: inline-block;
            width: 60px;
        }

        .input_query {
            width: 80px;
        }

        input, textarea {
            width: 160px;
            border: 1px solid #ccc;
            padding: 2px;
        }
    </style>
</head>

<body>

<div class="easyui-layout" data-options="fit:true">
    <!-- 查询条件  -->
    <div data-options="region:'north', title:'分布式锁配置表-条件'"
         style="height: 80px; padding: 5px 80px;display:none;">
        <form id="search-form">
            <table class="search-table">
                <tr>
                    <td>
                        <input type="text" id="query_uri" name="uri" class="easyui-validatebox" placeholder="Input uri">
                    </td>
                    <td>
                        状态::
                        <input class="easyui-combobox" name="status" id="query_status" style="width: 100px" data-options="
									valueField: 'id',
									textField: 'name',
									//multiple:true, //多选增加此项
									data: dict_status_all"/>
                    </td>
                    <td>
                        <a class="easyui-linkbutton"
                           data-options="iconCls:'icon-search'" id="search-btn">查询</a>
                        <a class="easyui-linkbutton"
                           data-options="iconCls:'icon-reload'" id="reset-btn">重置</a>
                    </td>

                </tr>
            </table>
        </form>
    </div>

    <!-- 查询结果 center -->
    <div data-options="region:'center', title:'查询结果'">
        <div id="toolbar" style="display:none;">
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true"
               onclick="onAdd()">新增</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="onEdit()">修改</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
               onclick="onDestroy()">删除</a>
        </div>
        <table id="dg" class="easyui-datagrid"
               data-options="fit:true, onDblClickRow:onDblClick, onClickRow:onClick, onLoadError:loadError, onLoadSuccess:function(){$('.datagrid-btable').find('div.datagrid-cell').css('text-align','left');}"
               toolbar="#toolbar" pagination="true"
               rownumbers="true" fitColumns="true" singleSelect="true" style="display:none;">
            <thead>
            <tr>
                <th align="center" field="id" width="50" sortable="true" hidden="true"></th>
                <th align="center" field="uri" width="100" sortable="true">uri</th>
                <th align="center" field="uriId" width="50" sortable="true" hidden="true">uriId</th>
                <th align="center" field="code" width="50" sortable="true">code</th>
                <th align="center" field="name" width="50" sortable="true">name</th>
                <th align="center" field="time" width="50" sortable="true">time</th>
                <th align="center" field="lockType" width="50" sortable="true" formatter="formatterReqLockType">Lock type</th>
                <th align="center" field="attrName" width="50" sortable="true">attrName</th>
                <th align="center" field="errMsg" width="50" sortable="true">errMsg</th>
                <th align="center" field="ifDel" width="50" sortable="true" hidden="true">是否删除</th>
                <th align="center" field="status" width="50" sortable="true" formatter="formatterStatus">状态</th>
                <th align="center" field="createTime" width="50" sortable="true" formatter="timestampFormatDateTime">创建时间</th>
                <th align="center" field="modifyTime" width="50" sortable="true" formatter="timestampFormatDateTime">修改时间</th>
                <th align="center" field="createUser" width="50" sortable="true" hidden="true">创建人</th>
                <th align="center" field="modifyUser" width="50" sortable="true">修改人</th>
                <th align="center" field="remark" width="50" sortable="true" hidden="true">备注</th>
            </tr>
            </thead>
        </table>
    </div>
</div>

<div id="dlg" class="easyui-dialog" style="width:400px;height:500px;padding:5px 10px;display:none;"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post" novalidate>
        <input type="hidden" name="id">
        <input type="hidden" name="uriId">
        <div class="fitem">
            <label>uri:</label>
            <input name="uri" class="easyui-validatebox" required="true" readonly="true" disabled="true">
        </div>
        <div class="fitem">
            <label>code:</label>
            <input name="code" class="easyui-validatebox" required="true" readonly="true" disabled="true">
        </div>
        <div class="fitem">
            <label>name:</label>
            <input name="name" class="easyui-validatebox">
        </div>
        <div class="fitem">
            <label>time:</label>
            <input name="time" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>Lock type:</label>
            <input class="easyui-combobox" name="lockType" id="dflLocks_lockType" required="true" data-options="
									valueField: 'id',
									textField: 'name',
									data: dict_reqLockType"/>
        </div>
        <div class="fitem">
            <label>attrName:</label>
            <input name="attrName" class="easyui-validatebox" >
        </div>
        <div class="fitem">
            <label>errMsg:</label>
            <input name="errMsg" class="easyui-validatebox">
        </div>
        <div class="fitem">
            <label>状态:</label>
            <input class="easyui-combobox" name="status" id="dflLocks_status" required="true" data-options="
									valueField: 'id',
									textField: 'name',
									data: dict_status"/>
        </div>
        <div class="fitem">
            <label>备注:</label>
            <textarea name="remark" style="height:60px;width:220px"></textarea>
        </div>
    </form>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="onSave()">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
           onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
    </div>
</div>

<script type="text/javascript">
    $('#search-btn').click(function () {
        doSearch();
    });
    $('#reset-btn').click(function () {
        $('#search-form')[0].reset();
    });

    $(function () {
        doSearch();
    });

    function doSearch() {
        var url="/dflcore/dflLocks/list2";
        var jsonParam = $('#search-form').serializeJson();
        $('#dg').datagrid({headers:app.headers, url: url, queryParams: jsonParam})
    }


    function doSearchReload() {
        var jsonParam = $('#search-form').serializeJson();
        $('#dg').datagrid('reload', jsonParam);
    }

    function onDblClick(rowIndex, rowData) {
        //alert('---onDblClick--rowIndex='+rowIndex+' row.id='+rowData.id);
        onEdit();
    }

    function onClick(rowIndex, rowData) {

    }

    function listenerName(ex) {
        if (ex.keyCode == 13) {
            doSearch();
        }
    }

    $('#query_code').keydown(listenerName);
    $('#query_name').keydown(listenerName);

    var url;

    function onAdd() {
        $('#dlg').dialog('open').dialog('setTitle', 'New DflLocks');
        $('#fm').form('clear');
        $('#dflLocks_status').combobox('select', '1');
        //$("#dflLocks_remark").val('test');
    }

    function getRowData(entityName, row) {
        var tmp;
        var obj = {}
        obj[entityName] = {};
        for (i in row) {
            tmp = row[i];
            obj[i] = tmp;
        }
        return obj;
    }

    function onEdit() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            var entityName = 'dflLocks';
            $('#fm').form('clear');
            var obj = getRowData(entityName, row);
            $('#dlg').dialog('open').dialog('setTitle', 'Edit DflLocks');
            $('#fm').form('load', obj);
        }

    }

    function onSave() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            if (row.canModify == 0) {
                $.messager.show({
                    title: 'Error',
                    msg: '不可修改，禁止操作'
                });
                return;
            }
        }
        var url = '/dflcore/dflLocks/save';
        var jsonParam = $('#fm').serializeJson();
        if ($('#fm').form('validate')) {
            $.ajax({
                method: 'post',
                url: url,
                data: jsonParam,
                headers: app.headers,
                dataType: 'json',
                success: function (result) {
                    if (result.success) {
                        $('#dlg').dialog('close');        // close the dialog
                        $.messager.show({
                            title: '系统消息',
                            msg: result.errorMsg
                        });
                        doSearchReload();    // reload the user data
                    } else {
                        $.messager.show({
                            title: '错误消息:' + result.resultCode,
                            msg: result.errorMsg
                        });
                    }
                },
                error: function (d, e) {
                    $.messager.show({
                        title: e,
                        msg: d.responseJSON.errorMsg,
                        timeout: 3000,
                        showType: 'slide'
                    });
                }
            });
        }
    }

    function onDestroy() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('删除确认', '你确定删除此记录?', function (r) {
                if (r) {
                    $.ajax({
                        type: 'post',
                        data: {id: row.id},
                        headers: app.headers,
                        dataType: 'json',
                        url: '/dflcore/dflLocks/delete',
                        success: function (data, textStatus, jqXHR) {
                            if (data.success) {
                                $.messager.show({    // show error message
                                    title: '系统消息',
                                    msg: '删除成功'
                                });
                                doSearchReload();    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: data.errorMsg
                                });
                            }
                        }
                    });
                }
            });
        } else {
            $.messager.show({
                title: '系统提示',
                msg: '请先选择要删除的记录'
            });
        }
    }
</script>
</body>
</html>